﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Workflows.Manipulation
{
    internal class MoveResult
    {
        Stage _stage;
        WFStep _step;

        public MoveResult(Stage stage, WFStep step)
        {
            _step = step;
            _stage = stage;
            _steps = new List<WFStep>();
        }

        public Stage CurrentStage
        {
            get { return _stage; }
        }

        public WFStep CurrentStep
        {
            get { return _step; }
        }

        private List<WFStep> _steps;
        /// <summary>
        /// Gets or sets newly created steps.
        /// </summary>
        public WFStep[] NewSteps
        {
            get { return _steps.ToArray(); }
        }

        List<Stage> _immediateStages;

        public Stage[] ImmediateStages
        {
            get
            {
                if (_immediateStages == null) return new Stage[0];
                else return _immediateStages.ToArray();
            }
        }

        public Stage[] GetNewStages()
        {
            Workflow wf = _stage.Workflow;
            return _steps.Select(o => wf.Stages[o]).ToArray();
        }

        internal void AddStep(WFStep step, bool isImmediate)
        {
            _steps.Add(step);
            if (isImmediate)
            {
                if (_immediateStages == null)
                    _immediateStages = new List<Stage>();
                _immediateStages.Add(_stage.Workflow.Stages[step]);
            }
        }

        internal void AddStep(UpcomingState upcoming)
        {
            this.AddStep(
                upcoming.Normal.UpcomingStep.Step,
                upcoming.Normal.IncomingStep.Step == _step
            );
        }

        public int NewStepCount
        {
            get { return _steps.Count; }
        }

    }
}
